#ifndef UDPSOCKET_H
#define UDPSOCKET_H

#ifdef _WIN32
	#include <Winsock2.h>
	#pragma comment(lib,"ws2_32.lib")
#else
	#include <sys/types.h>
	#include <netinet/in.h>
	#include <sys/socket.h>
	#include <errno.h>
	#include <arpa/inet.h>
	#include <unistd.h>
#endif

#include <stdio.h>

class UdpSocket
{
public:
	UdpSocket();
	~UdpSocket();

	bool setServer(const char *serverIP,int serverPort=0);
	bool bindPort(int nPort=0);	
	bool initSocket();
	int  sendData(const char *buf,int bufLen,const char *serverIP=NULL,int serverPort=0,int nTimeOut=-1); 
	int  recvData(char *buf, int bufLen, int nTimeOut=-1); 

	void closeUdpSocket();
	char* socketIP();
	int socketPort();
private:
	int  receive(unsigned char *szBuf,int nBufLength,int nTimeOut=-1);
	struct sockaddr_in serverAddr;
	int	 m_Socket;
	bool isInit;
	char* p_tempIP;
	int n_tempPort;

#ifdef _WIN32
	int m_len;
#else
	socklen_t m_len;
#endif
	
};
#endif
